home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / USB Software Locator Kit / SampleDriverInstallerExample / SampleDriverHeader1.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-22  |  4.9 KB  |  177 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        SampleDriverHeader.c
  3.  
  4.     Contains:    Sample Driver Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "SampleDriver.h"
  19. #include "SampleDriverVersion.h"
  20.  
  21. extern    usbSamplePBStruct mySamplePB;
  22.  
  23. //------------------------------------------------------
  24. //
  25. //    This is the driver description structure that the expert looks for first.
  26. //  If it's here, the information within is used to match the driver
  27. //  to the device whose descriptor was passed to the expert.
  28. //    Information in this block is also used by the expert when an
  29. //  entry is created in the Name Registry.
  30. //
  31. //------------------------------------------------------
  32. USBDriverDescription    TheUSBDriverDescription = 
  33. {
  34.     // Signature info
  35.     kTheUSBDriverDescriptionSignature,
  36.     kInitialUSBDriverDescriptor,
  37.     
  38.     // Device Info
  39.     0x0547,                                    // vendor = anchor
  40.     0x1002,                                    // product = not device specific
  41.     0,                                        // version of product = not device specific
  42.     0,                                        // protocol = not device specific
  43.     
  44.     // Interface Info    (* I don't think this would always be required...*)                
  45.     0,                                        // Configuration Value
  46.     0,                                        // Interface Number
  47.     0,                                        // Interface Class
  48.     0,                                         // Interface SubClass
  49.     0,                                        // Interface Protocol
  50.         
  51.     
  52.     // Driver Info
  53.     "\pUSBSampleDriver",                    // Driver name for Name Registry
  54.     0,                                        // Device Class  (from USBDeviceDefines.h)
  55.     0,                                        // Device Subclass 
  56.     kSampleHexMajorVers, 
  57.     kSampleHexMinorVers, 
  58.     kSampleCurrentRelease, 
  59.     kSampleReleaseStage,                    // version of driver  
  60.     
  61.     // Driver Loading Info
  62.     kUSBProtocolMustMatch+kUSBDoNotMatchInterface+kUSBDoNotMatchGenericDevice                    // Flags (currently undefined)
  63. };
  64.  
  65. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  66. {
  67.     kClassDriverPluginVersion,                // Version of this structure
  68.     SampleDriverValidateHW,                    // Hardware Validation Procedure
  69.     SampleDeviceInitialize,                    // Initialization Procedure
  70.     SampleInterfaceInitialize,                // Interface Initialization Procedure
  71.     SampleDriverFinalize,                    // Finalization Procedure
  72.     SampleDriverNotifyProc,                    // Driver Notification Procedure
  73. };
  74.     
  75.  
  76. // Hardware Validation
  77. // Called upon load by Expert
  78. OSStatus SampleDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  79. {
  80. #pragma unused (device)
  81. #pragma unused (desc)
  82.  
  83.     return (OSStatus)kUSBNoErr;
  84. }
  85.  
  86.  
  87. // Initialization function
  88. // Called upon load by Expert
  89. OSStatus     SampleDeviceInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  90. {
  91. #pragma unused (busPowerAvailable)
  92.  
  93.     DeviceInitialize(device, pDesc, busPowerAvailable);
  94.     return (OSStatus)kUSBNoErr;
  95. }
  96.  
  97.  
  98. // Interface Initialization Initialization function
  99. // Called upon load by Expert
  100. OSStatus     SampleInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  101. {
  102. #pragma unused (interfacenum)
  103. #pragma unused (pInterface)
  104. #pragma unused (pDesc)
  105. #pragma unused (device)
  106.  
  107.     return (OSStatus)noErr;
  108. }
  109.  
  110. // Termination function
  111. // Called by Expert when driver is being shut down
  112. OSStatus SampleDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  113. {
  114. #pragma unused (pDesc)
  115. OSStatus myErr;
  116.  
  117.     USBExpertStatus(theDeviceRef, "\pUSBSampleDriver: Finalize", theDeviceRef);
  118.     
  119.     if (mySamplePB.pipeRef)
  120.     {
  121.         USBExpertStatus(theDeviceRef, "\pUSBSampleDriver: Aborting interrupt pipe", theDeviceRef);
  122.         USBAbortPipeByReference(mySamplePB.pipeRef);
  123.     }
  124.     
  125.     mySamplePB.pb.usbReference = theDeviceRef;
  126.     mySamplePB.pb.pbVersion = kUSBCurrentPBVersion;
  127.     mySamplePB.pb.usbFlags = 0;
  128.     mySamplePB.pb.usbRefcon = 0;             
  129.     mySamplePB.pb.usbCompletion = (USBCompletion)-1;
  130.     
  131.     myErr = USBDeallocMem(&mySamplePB.pb);
  132.     
  133.     return (OSStatus)noErr;
  134. }
  135.  
  136. OSStatus    SampleDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  137. {
  138. #pragma unused (pointer)
  139. #pragma unused (notification)
  140. #pragma unused (refcon)
  141.     return(kUSBNoErr);
  142. }
  143.  
  144. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  145. {
  146. #pragma unused (pDeviceDescriptor)
  147. static Boolean beenThereDoneThat = false;
  148.  
  149.     USBExpertStatus(device, "\pUSBSampleDriver: Initialize", device);
  150.     if(beenThereDoneThat)
  151.     {
  152.         USBExpertFatalError(device, kUSBInternalErr, "\pSample driver is not reentrant!", 0);
  153.         return;
  154.     }
  155.     beenThereDoneThat = true;
  156.     
  157.     InitParamBlock(device, &mySamplePB.pb);
  158.     
  159.     mySamplePB.deviceRef = device;    
  160.  
  161.     mySamplePB.busPowerAvailable = busPowerAvailable;                            
  162.     mySamplePB.transDepth = 0;                            
  163.     mySamplePB.retryCount = kSampleRetryCount;
  164.     
  165.     mySamplePB.deviceRef = device;        
  166.     mySamplePB.interfaceRef = nil;        
  167.     mySamplePB.pipeRef = nil;        
  168.     
  169.     mySamplePB.pb.usbRefcon = kFindInterface;            
  170.     mySamplePB.pb.usbReference = device;
  171.     mySamplePB.pb.pbLength = sizeof(usbSamplePBStruct);
  172.  
  173.     InitParamBlock(device, &mySamplePB.pb);
  174.     InitiateTransactionProc(&mySamplePB.pb);
  175. }
  176.  
  177.